package ru.bragnikita.utils.swing.widget;

import javax.swing.*;
import java.awt.*;

class GridBagLayoutImplement
{
    JFrame jf;
    JPanel jp;
    JLabel name,city,state,marks;
    JTextField nameField, cityField, stateField, marksField;
    JButton submit;
    GridBagLayout gbl;
    GridBagConstraints gbc;

    public static void main(String[] args)
    {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new GridBagLayoutImplement().showBasicGui();
            }
        });
    }

    void showBasicGui(){
        jf = new JFrame("Student Details");
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        gbl = new GridBagLayout();
        gbc = new GridBagConstraints();
        jp = new JPanel();
        jp.setLayout(gbl);
        gbc.insets = new Insets( 5, 5, 5, 5 );      // <----- added
        gbc.anchor = GridBagConstraints.NORTHWEST;  // <----- added
        name = new JLabel("Name");
        gbc.ipadx = 1;
        gbc.ipady = 1;
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbl.setConstraints(name,gbc);
        jp.add(name);

        nameField = new JTextField(10);
        gbc.ipadx = 1;
        gbc.ipady = 1;
        gbc.gridx = 2;
        gbc.gridy = 0;
        gbl.setConstraints(nameField,gbc);
        jp.add(nameField);

        city = new JLabel("city!!!!!!!!!!!!");
        gbc.ipadx = 1;
        gbc.ipady = 1;
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbl.setConstraints(city,gbc);
        jp.add(city);

        cityField = new JTextField(10);
        gbc.ipadx = 1;
        gbc.ipady = 1;
        gbc.gridx = 2;
        gbc.gridy = 1;
        gbc.weighty = 1;    // <----- added
        gbl.setConstraints(cityField,gbc);
        jp.add(cityField);

        jf.add(jp, BorderLayout.WEST);  // <----- changed
        jf.setSize(300,300);
        jf.setVisible(true);


    }
}